<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查询新闻</title>
    <!--引入elementui得样式-->
    <link type="text/css" rel="stylesheet" href="/css/index.css" />
    <!--引入vue得依赖必须再elementui之前引入vue-->
    <script type="text/javascript" src="/js/vue.js"></script>
    <script type="text/javascript" src="/js/index.js"></script>
    <script type="text/javascript" src="/js/axios.min.js"></script>
    <script type="text/javascript" src="/js/qs.min.js"></script>
</head>
<body>
    <div id="app">
<!--        <el-button type="primary" @click="addNews">添加新闻</el-button>-->

        <!--模糊查询的表单-->
        <el-form :inline="true" :model="newsSearchForm" class="demo-form-inline">
            <el-form-item label="新闻题目">
                <el-input v-model="newsSearchForm.title" placeholder="请输入新闻题目"></el-input>
            </el-form-item>

            <el-form-item label="申报类型">
                <el-select v-model="newsSearchForm.kind" placeholder="请选择新闻类型" style="width: 200px;height: 50px">
                    <el-option
                            v-for="item in newsKinds"
                            :key="item.id"
                            :label="item.kind"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="发布者">
                <el-input v-model="newsSearchForm.author" placeholder="请输入审核人"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>
        <!--展示查询出来的新闻-->
        <el-table :data="tableData" border style="width: 100%">
            <el-table-column
                    prop="newId"
                    label="编号"
                    width="50">
            </el-table-column>
            <el-table-column
                    prop="title"
                    label="新闻标题"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="newsKinds.kind"
                    label="新闻种类"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="author"
                    label="新闻作者"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="time"
                    label="创建时间"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="approver"
                    label="审核人"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="approvetime"
                    label="审核时间"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="status"
                    label="状态"
                    width="200">
                <template slot-scope="scope">
                    <h4><span v-if="scope.row.status == 9" style="color:red;">待审核</span></h4>
                    <h4><span v-if="scope.row.status == 1" style="color: blue">审核已通过</span></h4>
                    <h4><span v-if="scope.row.status == 3" style="color: gray">审核不通过</span></h4>
                    <h4><span v-if="scope.row.status == 2" style="color: green">已上架</span></h4>
                    <h4><span v-if="scope.row.status == 4" style="color: gray">已下架</span></h4>
                </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作">
                <template slot-scope="scope">
                    <el-button size="mini"@click="xiangqing(scope.row)">新闻详情</el-button>
                    <el-button  type="success" @click="shangjia(scope.row)" v-if="scope.row.status==1 || scope.row.status==4">上架</el-button>
                    <el-button  type="danger" @click="xiajia(scope.row)" v-if="scope.row.status==2">下架</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--新闻详情弹出层-->
        <el-dialog
                title="新闻详情"
                :visible.sync="dialogVisible"
                width="70%"
                :before-close="handleClose">
            <el-descriptions class="margin-top"  :column="2" :size="size" border>
                <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-user"></i>
                        新闻标题
                    </template>
                    {{newsData.title}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-mobile-phone"></i>
                        新闻种类
                    </template>
                    {{newsData.kindName}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-location-outline"></i>
                        新闻作者
                    </template>
                    {{newsData.author}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-tickets"></i>
                        创建时间
                    </template>
                    {{newsData.time}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-tickets"></i>
                        审核人
                    </template>
                    {{newsData.approver}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-tickets"></i>
                        审核时间
                    </template>
                    {{newsData.approvetime}}
                </el-descriptions-item>
            </el-descriptions>
            <el-form :label-position="labelPosition" label-width="80px" :model="newsData">
                <el-form-item label="新闻内容:">
                    <el-input readonly="readonly" type="textarea" :rows="3" v-model="newsData.content"></el-input>
                </el-form-item>
            </el-form>
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>
        <!--分页-->
        <div id="fenye">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[1,2,3,5]"
                    :page-size="pageSize"
                    :total="total"
                    layout="total, sizes, prev, pager, next, jumper">
            </el-pagination>
        </div>
    </div>
</body>
<script>
    var app = new Vue({
        el:"#app",
        data:{
            tableData:[],
            //新闻类型
            newsKinds:[],
            //当前显示的页码
            currentPage:1,
            //总条数
            total:0,
            //每页显示的条数
            pageSize:5,
            //搜索表单对象
            newsSearchForm:{},
            dialogVisible:false,
            newsData:{},
            labelPosition: 'top',
        },
        created(){
           this.showtable();
           this.showAllNewsKinds();
        },
        methods:{
            xiangqing(row){
                this.dialogVisible=true;
                this.newsData=row;
            },
            shangjia(row){
                row.status=2;
                axios.post("news/putAwayNews",row).then(resp=>{
                    this.$message.success("已上架");
                    this.showtable();
                })
            },
            xiajia(row){
                row.status=4;
                axios.post("news/putAwayNews",row).then(resp=>{
                    this.$message.success("已下架");
                    this.showtable();
                })
            },

            showtable(){
                axios.post("news/all1?currentPage="+this.currentPage+"&pageSize="+this.pageSize,this.newsSearchForm).then(resp=>{
                    console.log(resp.data.data)
                    this.tableData=resp.data.data.list;
                    //把查询出来的总条数赋值给total
                    this.total=resp.data.data.total;
                })
            },
            showAllNewsKinds(){
                axios.post("newskinds/list").then(resp=>{
                    this.newsKinds=resp.data.data;
                })
            },
            onSubmit(){
                this.currentPage=1;
                this.showtable();
            },
            //点击处理页码大小变动时候触发的事件
            handleSizeChange(val) {
                //点击切换每页显示的条数时，把每页的显示条数的值重新赋值给pageSize
                this.pageSize=val;
                this.showtable();
            },
            //点击处理当前页变动时候触发的事件。
            handleCurrentChange(val) {
                //点击到第几页是，把当前是第几页的值重新赋值给currentPage
                this.currentPage=val;
                this.showtable();
            },
        }
    })
</script>
<style>
    #fenye{
        margin: 20px auto;
    }
</style>
</html>